﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAL;
using DTO;
namespace BUS
{
   public class BO_DEMBUS
    {
        public static void Insert(BO_DEM trinhduyet)
        {
            BO_DEMDAL boDAL = new BO_DEMDAL();
            boDAL.Insert(trinhduyet);

        }
        public static void Update(BO_DEM trinhduyet)
        {
            BO_DEMDAL boDAL = new BO_DEMDAL();
            boDAL.Update(trinhduyet);
        }
        public static void Delete(int Ma)
        {
            BO_DEMDAL boDAL = new BO_DEMDAL();
            boDAL.Delete(Ma);
        }
        public static Bo_demColection GET(string Where, int PageIndex, int PageSize,
                                          string OrderBy, string OrderDirection,
                                          out int TotalRecords)
        {
            BO_DEMDAL boDAL = new BO_DEMDAL();
            return boDAL.GET(Where, PageIndex, PageSize, OrderBy, OrderDirection, out TotalRecords);
        }
        public static int so_luong_hom_nay()
        {
            string from = DateTime.Now.ToString("M/d/yyyy 00:00:01");
            string to = DateTime.Now.ToString("M/d/yyyy 23:59:59");
            BO_DEMDAL adDAL = new BO_DEMDAL();
            return adDAL.so_luong_hom_nay(from, to);
        }
        public static int so_luong_theo_ngay(DateTime ngay)
        {
            string from = ngay.ToString("M/d/yyyy 00:00:01");
            string to = ngay.ToString("M/d/yyyy 23:59:59");
            BO_DEMDAL adDAL = new BO_DEMDAL();
            return adDAL.so_luong_hom_nay(from, to);
        }
        public static int so_luong_hom_qua()
        {
            string from = DateTime.Now.AddDays(-1).ToString("M/d/yyyy 00:00:01");
            string to = DateTime.Now.AddDays(-1).ToString("M/d/yyyy 23:59:59");
            BO_DEMDAL adDAL = new BO_DEMDAL();
            return adDAL.so_luong_hom_nay(from, to);
        }
        public static int Day(string c)
        {
            int rs = 0;
            switch (c)
            {
                case "Mon": rs = 1; break;
                case "Tue": rs = 2; break;
                case "Wed": rs = 3; break;
                case "Thu": rs = 4; break;
                case "Fri": rs = 5; break;
                case "Sat": rs = 6; break;
                case "Sun": rs = 7; break;
                default: rs = 0; break;
            }
            return rs;
        }
        public static int so_luong_tuan_nay()
        {
           
            int x = Day(DateTime.Now.ToString("ddd")) -1;
            string from = DateTime.Now.AddDays(-x).ToString("M/d/yyyy 00:00:01");
            string to = DateTime.Now.ToString("M/d/yyyy 23:59:59");
            BO_DEMDAL adDAL = new BO_DEMDAL();
            return adDAL.so_luong_hom_nay(from, to);
        }

        public static int so_luong_thang_nay()
        {
            string from = DateTime.Now.ToString("M/01/yyyy 00:00:01");
            string to = DateTime.Now.ToString("M/d/yyyy 23:59:59");
            BO_DEMDAL adDAL = new BO_DEMDAL();
            return adDAL.so_luong_hom_nay(from, to);
        }

        public static BO_DEM GetByID(int MA)
        {
            int t = 0;
            BO_DEMDAL boDAL = new BO_DEMDAL();
            Bo_demColection bdcl = boDAL.GET("where " + Bo_demColumns.Ma.ToString() + " = " + MA.ToString(), 0, 0,
               Bo_demColumns.Ma.ToString(), "ASC", out t);
            if (bdcl.Count == 1)
                return bdcl[0];
            return null;
        }

        public static Bo_demColection GetAll()
        {
            int t = 0;
            BO_DEMDAL boDAL = new BO_DEMDAL();
            return boDAL.GET("where 1=1", 0, 10, Bo_demColumns.Ma.ToString(), "ASC", out t);
        }
    }
}
